<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>htmlcss 阶段</title>
    <style></style>
</head>

<body>



    <script>
        // 体检数据：
        var data = [
            { name: "孙清瑶", sex: "女", weight: 116 },
            { name: "向君泽", sex: "男", weight: 140 },
            { name: "曾洛伊", sex: "女", weight: 126 },
            { name: "李青丝", sex: "女", weight: 96 },
            { name: "陈伟成", sex: "男", weight: 150 },
            { name: "张浩然", sex: "男", weight: 98 }
        ]


        // 面向对象
        // 构造函数 Exam， 创建构造函数的实例对象 obj ;
        // 添加属性 
        // data(数据)  ,role(值固定为110)
        function Exam() {
            // 编写你的代码
            this.role = 110;
            this.recognizeSex = function (name) {
                for (i = 0; i < data.length; i++) {
                    // console.log(data[2].name);
                    if (name == data[i].name) {
                        this.data = data[i];
                        console.log(this.data.name + "是" + this.data.sex);
                    }
                }
            }
            this.testWeight = function (name) {
                // this.role = 110;
                var too = "";
                for (i = 0; i < data.length; i++) {
                    if(data[i].name==name){
                        if (data[i].sex == "女") {
                            too = "她";
                        } else {
                            too = "他";
                        }
                        // console.log(data[i].sex);s
                        if (data[i].weight > this.role) {
                            console.log(too + "是胖子");
                        } else {
                            console.log(too + "不是胖子");
                        }
                    }
                    
                }
            }
        }

        // 实例对象
        var obj = new Exam();
        console.log(obj.role);
        obj.recognizeSex("孙清瑶");
        // obj.testWeight("孙清瑶");
        obj.testWeight("向君泽");
        obj.testWeight("李青丝");
            // 添加方法recognizeSex, 调用该方法时，通过输入名单中的姓名判断性别,在控制台提示.
            // 例如：孙清瑶是女生 
            // obj.recognizeSex("孙清瑶");// 孙清瑶是女生
            // obj.recognizeSex("向君泽");// 孙清瑶是男生


            // 添加方法testWeight 通过输入名单中的姓名判断是否为胖子,假设体重超过了110斤为胖子 (rule: 110) 
            // obj.testWeight("向君泽");// 他是胖子
            // obj.testWeight("李青丝");// 她不是是胖子

    </script>
</body>

</html>